class Solution(object):
    def numberOfArrays(self, differences, lower, upper):
        n = len(differences)
        for i in range(1, n):
            differences[i] += differences[i - 1]
        differences.append(0)
        r = upper - lower - (max(differences, 0) - min(differences, 0))
        return max(r + 1, 0)